<?php


namespace app\index\model;


use think\Model;

class Menu extends Model
{
    public static function getMenuList(){
        $MenuClass=new self();
        $data=$MenuClass->where('del_flag',0)->field('id,menu_name,menu_level,p_id')->order('p_id,id')->select()->toArray();
        $menu_list=[];
        foreach ($data as $key=>$value){
            if($value['menu_level']===1 && !isset($menu_list[$value['id']])){
                $menu_list[$value['id']]=['label'=>$value['menu_name'],'value'=>$value['id']];
            }else if ($value['menu_level']===2){
                $menu_list[$value['p_id']]['children'][]=['label'=>$value['menu_name'],'value'=>$value['id']];
            }
        }
        $menu_list=array_values($menu_list);
        return $menu_list;
    }
}